<admintpl file="header" />
</head>
<body>
<?php
	if(isset($add_from) && $add_from == 1)
	{
		$add_from = 1;
	}else
	{
		$add_from = 0;
	}
?>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <if condition="$add_from eq 1">
            <li>
                <!--<a href="{:U('Admin/NewsManage/publish', array('live_id'=>$live['live_id'],'news_id'=>$news_id, $id_type=>$id_val,'add_from'=>1))}">新闻详情</a>-->
                <a href="{:U('Admin/News/editapi', array('live_id'=>$live['live_id'],'news_id'=>$news_id, $id_type=>$id_val,'add_from'=>1))}" >新闻详情</a>
            </li>
            <li><a href="{:U('Admin/live/edit',array('live_id'=>$live['live_id'],'news_id'=>$news_id,$id_type=>$id_val,'add_from'=>1))}">直播详情</a></li>
            <li class="active"><a href="{:U('Admin/live/manage', array('news_id'=>$news_id, $id_type=>$id_val,'add_from'=>1))}">管理</a></li>
        </if>
        <span style="float: right; margin-right:100px;"> <a href="{:U('Admin/news/index', array($id_type=>$id_val))}">返回栏目新闻列表</a></span>
    </ul>

    <php>
        $status = array("2"=>'直播结束',"3"=>'未开始',"4"=>'正在直播',"5"=>'直播回顾');
    </php>
    <form class="js-ajax-form" action="" method="post">
        <table class="table table-hover table-bordered">
            <tbody>
                <tr>
                    <td>直播开始时间</td>
                    <td>{$live['start_time']}</td>
                </tr>
                <tr>
                    <td>URL</td>
                    <td>id={$live['live_id']}&type=live
                        <a style="margin-left: 20px;" class="link_url" data-clipboard-text="id={$live['live_id']}&type=live" title="id={$live['live_id']}&type=live" href="javascript:;" >复制</a>
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>{$status[$live['status']]}
                        <if condition="$live.status neq 3">
                            <a class="set_status" data-id="{$live.live_id}" data-status="{$live.status}" href='{:U("Admin/Live/set_status", array("live_id"=>$live["live_id"],"news_id"=>$news_id, $id_type=>$id_val,"add_from"=>1))}'>更新状态</a>
                        </if>
                    </td>
                </tr>
                <tr>
                    <td>观看人数</td>
                    <td><input type="text" name="weight" id="weight{$live.live_id}" value="{$live.play_count}" disabled="disabled" size="2"  class="input_edit">
                        <a id="edit_weight_{$live.live_id}" href='javascript:void(0);' onclick="update_live_count('{$live.live_id}','live')" class="edit_sub">修改</a>
                        <input type="hidden" name="old_weight" id="old_weight_{$live.live_id}" value="{$live.play_count}">
                    </td>
                </tr>
                <?php $live_category = array(0=>'3',1=>'4',2=>'5',3=>'7'); ?>
                <tr>
                    <td>其它操作</td>
                    <td>
                        <a href='{:U("Admin/Live/direct_manage", array("live_id"=>$live["live_id"],"add_from"=>1))}'>导播管理</a>

                        <?php if(in_array($live['category'],$live_category)){ ?>
                            <a href='{:U("Admin/LiveGraphic/live_panel", array("live_id"=>$live["live_id"],"add_from"=>1))}'>直播员面板</a>
                        <?php } ?>
                        
                        <?php if($live['category']==7){ ?>
                            <a href='{:U("Admin/FriendCircle/index", array("live_id"=>$live["live_id"],"add_from"=>1))}'>汇友圈管理</a>
                        <?php } ?>

                        <if condition="$live.quiz_status eq 1">
                            <a href='{:U("Admin/Guest/index", array("live_id"=>$live["live_id"]))}'>竞猜管理</a>
                        </if>

                        <if condition="$live.is_props neq 0">
                            <a href='{:U("Admin/Prop/index", array("live_id"=>$live["live_id"]))}'>打赏管理</a>
                        </if>

                        <if condition="$live.news_status neq 0">
                            <a href='{:U("Admin/Live/news_relation", array("live_id"=>$live["live_id"],"add_from"=>1))}'>相关新闻</a>
                        </if>

                    </td>
                </tr>
            </tbody>
        </table>
    </form>

</div>
<script src="__PUBLIC__/js/common.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/ueditor/third-party/zeroclipboard/ZeroClipboard.min.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    $(document).ready(function(){
        $('input[name="query_form_btn"]').click(function(){
            $('#query_form').attr('action', $(this).attr('data-action'));
            $('#query_form').submit();
        });

        var clip = new ZeroClipboard($("td .link_url"));
        clip.on("aftercopy", function(e){
            layer.msg('复制成功！');
            //alert('复制成功！');
        });
        $('#typeId').val({$formParam.typeId});

        $('.set_result').click(function(e){
            e.preventDefault();
            $_this = this;
            var live_id = $($_this).attr('data-id');
            var red_competitor_id = $($_this).attr('data-red-id');
            var blue_competitor_id = $($_this).attr('data-blue-id');

            $.getJSON('{:U("Admin/Live/get_competitor")}&red_competitor_id='+red_competitor_id+'&blue_competitor_id='+blue_competitor_id).done(function (data) {
                if (data.state === 'success') {
                    var href = $($_this).prop('href');
                    var contentHtml = "<div style='width:220px;height:100px;padding:0px 10px;'><div style='width:80px;float:left;text-align:center;'><div style='width:80px; height:80px; border-radius:50%; overflow:hidden;'><img src="+
                            data.info.red.avatar+" style='width:80px;height:80px;'></div><span>"+
                            data.info.red.real_name+"</span></div><div style='width:80px;float:right;text-align:center;'><div style='width:80px; height:80px; border-radius:50%; overflow:hidden;'><img src="+
                            data.info.blue.avatar+" style='width:80px;height:80px;'></div><span>"+
                            data.info.blue.real_name+"</span></div><div style='width:220px;float:left;margin-top:10px;text-align:center;'><input id='red_score' style='width:75px;'><span style='font-family:Bold;font-weight:900;width:20px;margin-left:20px;margin-right:20px;'>：</span><input id='blue_score' style='width:75px;'></div></div>";

                    art.dialog({
                        title: "更新比分",
                        icon: '',
                        content: contentHtml,
                        close: function () {
                            $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                            return true;
                        },
                        okVal:"确定",
                        ok: function () {
                            var red_score = $('#red_score').val();
                            var blue_score = $('#blue_score').val();
                            if(red_score == '' || blue_score == ''){
                                layer.msg('请输入比赛结果！');
                                return false;
                            }

                            var g = /^[1-9]*[1-9][0-9]*$/;
                            if(!g.test(red_score)){
                                layer.msg('请输入整数！');
                                return false;
                            }
                            if(!g.test(blue_score)){
                                layer.msg('请输入整数！');
                                return false;
                            }

                            art.dialog({
                                title: false,
                                icon: 'question',
                                content: '您确定要将比分设定为 ' + red_score+ '（' + data.info.red.real_name + '）：' + blue_score + '（' + data.info.blue.real_name+'）吗？',
                                close: function () {
                                },
                                okVal:"确定",
                                ok: function () {
                                    $.getJSON(href+'&live_id=' + live_id+'&red_score='+red_score+'&blue_score='+blue_score).done(function (data) {
                                        if (data.state === 'success') {
                                            if (data.referer) {
                                                location.href = data.referer;
                                            } else {
                                                reloadPage(window);
                                            }
                                        } else if (data.state === 'fail') {
                                            art.dialog({
                                                content: data.info,
                                                icon: 'warning',
                                                ok: function () {
                                                    this.title(data.info);
                                                    return true;
                                                }
                                            });
                                        }
                                    });
                                    return true;
                                },
                                cancelVal: '关闭',
                                cancel: true
                            });
                        },
                        cancelVal: '关闭',
                        cancel: true
                    });
                }
            });
        });

        $('.set_status').click(function(e){
            e.preventDefault();
            $_this = this;
            var live_id = $($_this).attr('data-id');
            var status = $($_this).attr('data-status');

            var href = $($_this).prop('href');

            var contentHtml = "<select id='update_status' style='width:180px;'><option value='0'>--请选择--</option>";

            if(2 == status){
                contentHtml += "<option value='4' id='status_option_4'>正在直播</option><option value='5' id='status_option_5'>直播回顾</option>";
            }else if(4 == status){
                contentHtml += "<option value='2' id='status_option_2'>直播结束</option><option value='5' id='status_option_5'>直播回顾</option>";
            }else{
                contentHtml += "<option value='4' id='status_option_4'>正在直播</option><option value='2' id='status_option_2'>直播结束</option>";
            }
            contentHtml += "</select>";

            art.dialog({
                title: "更新状态",
                icon: '',
                content: contentHtml,
                close: function () {
                    $_this.focus(); //关闭时让触发弹窗的元素获取焦点
                    return true;
                },
                okVal:"确定",
                ok: function () {
                    var update_status = $('#update_status').val();
                    if(update_status == 0){
                        layer.msg('请选择直播状态！');
                        return false;
                    }
                    var status_text = $('#status_option_'+update_status).text();
                    art.dialog({
                        title: false,
                        icon: 'question',
                        content: '您确定要将直播状态设置为【' + status_text +'】吗？',
                        close: function () {
                        },
                        okVal:"确定",
                        ok: function () {
                            $.getJSON(href+'&live_id=' + live_id+'&status='+update_status).done(function (data) {
                                if (data.state === 'success') {
                                    if (data.referer) {
                                        location.href = data.referer;
                                    } else {
                                        reloadPage(window);
                                    }
                                } else if (data.state === 'fail') {
                                    art.dialog({
                                        content: data.info,
                                        icon: 'warning',
                                        ok: function () {
                                            this.title(data.info);
                                            return true;
                                        }
                                    });
                                }
                            });
                            return true;
                        },
                        cancelVal: '关闭',
                        cancel: true
                    });
                },
                cancelVal: '关闭',
                cancel: true
            });
        });


    });



    function update_live_count(type_id,type){
        if(type == 'live'){
            edit_column = $("#edit_weight_"+type_id).html();
            column_befor = $("#old_weight_"+type_id).val();//原权重值
            column  = $("#weight"+type_id).val(); //现权重值
            now_input_type = $("#weight" + type_id); //权重 ID
            now_edit_type  = $("#edit_weight_" + type_id);  //修改 按钮ID
            live_id = type_id;
        }

        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == name){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                $.ajax({
                    type: "POST",
                    cache: false,
                    data: "type="+type+"&live_id="+live_id+"&old_val="+column_befor+"&val="+column,
                    async: false,
                    url: "{:U('Live/editLiveCount')}",
                    success: function(ret) {
                        if(ret['code'] == 200){
                            now_input_type.attr("disabled", "disabled");
                            now_edit_type.html("修改");
                            location.reload()
                        }else{
                            alert(ret.msg)
                        }
                    }, error: function(data) {
                        alert('网络错误，请稍后再试！');
                    }
                });
            }
        }
    }



</script>
</body>
</html>